/*
 * @Author: ChunLai
 * @Date: 2023-07-25 09:48:14
 * @LastEditTime: 2025-11-27 15:53:56
 * @Description:页面公共数据配置
 * @FilePath: \01.latest-short-insure\src\store\modules\page.js
 */

const state = {
  /* ===== 首页 ===== */
  // 投保前置页 - 客户告知弹窗内容配置
  productNoticesList: [],
  // 投保声明文件(confirmBook接口没有返回文件时,配置使用)(利安)
  insureStateList: [],
  comClauseList: [], // 保司公共文件(利安)
  // 通用理赔(接口没有返回使用)
  lipeicontent: "",
  baosiHtml: "", // 详情图下特殊文本配置(利安)
  dutysConfig: [], // 特殊责任配置(利安)
  insuQuDao: "1", // 投保渠道 1：分享网格保；0分享直接投 2:app内可投
  // noInsCount: false, // 无保费试算
  /* ===== 投保前确认 ===== */
  presureCfg: [],
  tgForInsureLink: [], // 配置无权限，推广员可直接投保的（不走客服模式）
  tgNoneInsuAgent: [], // 配置无权限，推广员可直接投保的（特殊人员走客服模式）
  /* ===== 客户信息输入 ===== */
  // 1.用户信息填写规则
  nameMaxLength: 30, // 姓名校验最大长度
  occuDisLevelMin: 10,
  occuDisLevelArr: [],
  apiGetBanks: "0", // 平安接口获取银行列表
  // 隔代年龄差距
  ageInterval: 18,
  // 被保险人
  bbrAddItemMax: 1, // 最大个数（最小为1）
  fieldDescConfig: {}, // 字段描述配置
  field2Desc: [], // 字段保司内配置
  limitFeeObj: {}, // 银行卡限额数据
  socialName: "有无社保",
  /* ===== 续保 ===== */
  unifyRenew: "0", // 是否有
  renewBank: "1", // 1有 0无
  //
  autoRenewNotice: {
    label: "扣款授权协议",
    name: "《扣款授权协议》",
    type: "link", // link html pdf
    cont: "",
  },
  /* ===== 规则校验字段 ===== */
  idImgNotCheck: [], // 证件类型上传非校验字段
  noneCheckFields: [], // 非必填字段不校验
  effectiveDate: "0",
  beginInsDay: 0, // 有效日T+4
  startDateDiff: -1,
  signTarget: [], //签名对象
  /* ===== 投保告知 ===== */
  gaoZhiType: "0", // 0没有；1互联网（评估问卷）
};

const getters = {
  pageConfigs: (state) => state,
  gaoZhiType: (state) => state.gaoZhiType,
  lipeicontent: (state) => state.lipeicontent,
  productNoticesList: (state) => state.productNoticesList,
  insureStateList: (state) => state.insureStateList,
  comClauseList: (state) => state.comClauseList,
  presureCfg: (state) => state.presureCfg,
  baosiHtml: (state) => state.baosiHtml,
  insuQuDao: (state) => state.insuQuDao,
  dutysConfig: (state) => state.dutysConfig,
  effectiveDate: (state) => state.effectiveDate,
  startDateDiff: (state) => state.startDateDiff,
  socialName: (state) => state.socialName,

  beginInsDay: (state) => state.beginInsDay,
  noneCheckFields: (state) => state.noneCheckFields,
  idImgNotCheck: (state) => state.idImgNotCheck,
  occuDisLevelMin: (state) => state.occuDisLevelMin,
  occuDisLevelArr: (state) => state.occuDisLevelArr,

  signTarget: (state) => state.signTarget,
  apiGetBanks: (state) => state.apiGetBanks,
  bbrAddItemMax: (state) => state.bbrAddItemMax,

  field2Desc: (state) => state.field2Desc,
  fieldDescConfig: (state) => state.fieldDescConfig,
  limitFeeObj: (state) => state.limitFeeObj,

  unifyRenew: (state) => state.unifyRenew,
  renewBank: (state) => state.renewBank,
  autoRenewNotice: (state) => state.autoRenewNotice,
  tgForInsureLink: (state) => state.tgForInsureLink,
  tgNoneInsuAgent: (state) => state.tgNoneInsuAgent,
};

const mutations = {
  SET_PAGE_CONFIG(state, payload) {
    Object.assign(state, payload);
  },
  // 合并字段
  MERGE_STATE_CONFIG(state, payload) {
    for (const key in payload) {
      state[key] = payload[key];
    }
  },
  SET_INSURE_CONFIG(state, payload = {}) {
    state.fieldDescConfig = payload;
  },
};
const actions = {
  initPageConfig({ state, commit }, data) {
    // console.log('page/initPageConfig', data);
    const noticeKey = ["autoHealthy"],
      homeKey = ["recordName", "insuPlan"];
    for (const key in data) {
      let obj = {};
      obj[key] = data[key];
      if (noticeKey.includes(key)) {
        commit("notice/SET_STATE_FIELD", obj, { root: true });
      } else if (homeKey.includes(key)) {
        commit("home/updateField", obj, { root: true });
      } else {
        if (key === "comClauseList") {
          let arr = [...state.comClauseList, ...data.comClauseList];
          commit("MERGE_STATE_CONFIG", { comClauseList: arr });
        } else {
          commit("MERGE_STATE_CONFIG", obj);
        }
      }
    }
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
